import listStatus from '../../public/js/way-list-status.js';
import carStatus from './car-item-status.js';
export default {
	data() {
		return {
			emptyType: 'order',
			emptyShow: false,
			pagenum: 1,
			pagesize: 10,
			downOption: {
				auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
			},
			upOption: {
				auto: false, // 不自动加载
				// page: {
				// 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
				// 	size: 10 // 每页数据的数量
				// },
				noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
				empty: {
					tip: '~ 暂无订单 ~', // 提示
					btnText: '去逛逛'
				}
			},
			categoryId: '',
			orderList: [], //列表数据
			canIUseGetUserProfile: false,
			ewmimage: '',
		};
	},
	props: {
		i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
		index: {
			// 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
			type: Number,
			default () {
				return 0;
			}
		},
		listTop: {
			type: Number,
			default () {
				return 10;
			}
		},
		skeyword: {
			type: String,
			default () {
				return '';
			}
		},
		tabObj: {
			type: Object,
			default () {
				return;
			}
		}
	},
	watch: {
		skeyword(newVal, oldVal) {
			if (newVal) {
				// this.mescroll.resetUpScroll()
			}
		}
	},
	created() {
		//加判断 编辑页来的，请求列表接口
		// #ifdef MP-WEIXIN
		if (wx.getUserProfile) this.canIUseGetUserProfile = true;
		// #endif
	},
	methods: {
		getDepartBtnShow(rows) {
			if (listStatus.getUploadLevelBtnShow(rows) == 1 || listStatus.getUploadLevelBtnShow(rows) == 2) {
				return true;
			}
			return false;
		},
		getAllocationBtnShow(rows) {
			if (listStatus.getUploadLevelBtnShow(rows) == 0) {
				return true;
			}
			return false;
		},
		getSelect(row) {
			return listStatus.getSelect(row);
		},
		waybillStatus(rows) {
			return listStatus.status(rows);
		},
		getStatusP2(rows) {
			return listStatus.getStatusP2(rows);
		},
		getLevel(rows) {
			return listStatus.getLevel(rows);
		},
		getStatus(rows) {
			return listStatus.getStatus(rows);
		},
		getTransitStatus(rows) {
			return listStatus.getTransitStatus(rows);
		},
		getDestinationCity(rows) {
			return listStatus.getDestinationCity(rows);
		},
		getDisabledDel(rows) {
			return listStatus.getDisabledEdit(rows);
		},
		getDisabledEdit(rows) {
			return listStatus.getDisabledEdit(rows);
		},
		getDepartPic1(rows) {
			return listStatus.getDepartPic1(rows);
		},
		getDepartPic2(rows) {
			return listStatus.getDepartPic2(rows);
		},
		getArrivePic1(rows) {
			return listStatus.getArrivePic1(rows);
		},
		getAllocatePic1(rows) {
			return listStatus.getAllocatePic1(rows);
		},
		getAllocatePic2(rows) {
			return listStatus.getAllocatePic2(rows);
		},
		carLoading(e) {
			this.$util.redirectTo('/pages/order/order-confirm/order-depart-confirm', e, null, 'obj');
		},
		toDetail(item) {
			this.$util.redirectTo('/pages/order/order-detail/order-detail', {
				waybill_id: item.waybill_id,
				in_type: '1',
			});
		},
		
		getCarShowStatus(rows){
			return carStatus.getCarShowStatus(rows)
		},
		getAllocateImgBtnShow(rows){
			return carStatus.getAllocateImgBtnShow(rows)
		},
		getAllocationBtnShow(rows){
			return carStatus.getAllocationBtnShow(rows)
		},
		getArriveBtnShow(rows){
			return carStatus.getArriveBtnShow(rows)
		},
		getPayBtnShow(rows){
			return carStatus.getPayBtnShow(rows)
		},
		getAddBtnShow(rows){
			return carStatus.getAddBtnShow(rows)
		}, 
		getSignBtnShow(rows){
			return carStatus.getSignBtnShow(rows)
		}, 
		allocationClick(e){
			this.$util.redirectTo('/pages/waybill/allocation/allocation-no-plat',e,null,'obj');
		},
		arriveClick(e){
			let that = this;
			uni.showModal({
				title: '到货',
				content: '是否继续操作？',
				confirmText: '确定',
				success: res => {
					if (res.confirm) {
					 that.arriveLoadData(e);
					}  
				}
			});
		},
		payClick(e){
			let that = this;
			uni.showModal({
				title: '支付',
				content: '是否继续操作？',
				confirmText: '确定',
				success: res => {
					if (res.confirm) {
					 that.payLoadData(e);
					}  
				}
			});
		},
		addClick(e){
			this.$util.redirectTo('/pages/waybill/allocation/allocation-add-track', {
				waybill_id: e.waybill_id,
			});
		},
		signClick(e){
			let that = this;
			uni.showModal({
				title: '签收',
				content: '是否继续操作？',
				confirmText: '确定',
				success: res => {
					if (res.confirm) {
					 that.signLoadData(e);
					}  
				}
			});
		},
		arriveLoadData(e) {
			var data = {
				waybill_ids: e.waybill_id,
			}; 
			this.http.sendRequest({
				api: this.api.order.allocationReach,
				data: data,
				success: res => { 
					let msg = res.message;
					if (res.code == '1') {
						this.getOrderListData();
					} else {
						this.$util.showToast({
							title: msg
						});
					} 
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				},
				fail: res => {
					 
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});	 
		},
		payLoadData(e) {
			var data = {
				waybill_ids: e.waybill_id,
			}; 
			this.http.sendRequest({
				api: this.api.order.allocationPayStatus,
				data: data,
				success: res => { 
					let msg = res.message;
					if (res.code == '1') {
						 this.getOrderListData();
					} else {
						uni.showToast({
							title: msg
						});
					} 
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				},
				fail: res => {
					 
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});	 
		},
		signLoadData(e) {
			var data = {
				waybill_ids: e.waybill_id,
			}; 
			this.http.sendRequest({
				api: this.api.order.allocationSignFor,
				data: data,
				success: res => { 
					let msg = res.message;
					if (res.code == '1') {
						 this.getOrderListData();
					} else {
						this.$util.showToast({
							title: msg
						});
					} 
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				},
				fail: res => {
					 
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});	 
		},
		
		/*下拉刷新的回调 */
		downCallback() {
			this.pagenum = 1;
			// this.pagesize = 1;
			this.mescroll.resetUpScroll();
		},
		/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
		upCallback(page) {
			this.pagenum = page.num;
			this.pagesize = page.size;
			this.getOrderListData();
		},
		//点击空布局按钮的回调
		emptyClick() {
			this.$util.redirectTo('/pages/index/index/index', {}, 'redirectTo');
		},
		getJourneyStatus(rows, prop) {
			let str = "";
			switch (rows.journey_status) {
				case "20":
					str = "已发车";
					break;
				case "30":
					str = "已送达";
					break;
			}
			return str;
		},

		getProvinceCityCounty(rows) {
			// let province = this.helper.strNullReplace(rows.to_province, "");
			let city = this.check.strNullReplace(rows.to_city, "");
			let county = this.check.strNullReplace(rows.to_county, "");
			return city + '-' + county;
		},
		getOrderListData(type) {
			let level = uni.getStorageSync(this.preutils.accountLevel);
			// if (level == 1 || level == 0) {
			// 	this.carListData(type);
			// } else{
			// 	this.orderList = [];
			// 	this.mescroll.endSuccess(this.orderList.length);  
			// 	this.emptyType = 'order';
			// 	this.emptyShow = true;
			// 	// if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
			// }
			if(this.tabObj.status > 20){
				this.allocationListLoadData();
			}else{
				this.carListData(type);
			}
			
		},

		carListData(type) {
			if (!this.check.isLogin()) { 
				return
			}
			var data = {
				journey_status: this.tabObj.status,
				page: this.pagenum,
				page_size:this.pagesize, 
			};
			let level = uni.getStorageSync(this.preutils.accountLevel);
			if (level == 1) {
				var userinfo= uni.getStorageSync(this.preutils.userinfo)
				data.destination_site_id = userinfo.site_id;
			}
			this.emptyShow = false;
			// if (this.$refs.loadingCover) this.$refs.loadingCover.show;
			this.http.sendRequest({
				api: this.api.order.journeyList,
				data: data,
				success: res => {
					this.emptyShow = true;
					this.emptyType = 'order';
					let newArr = [];
					let msg = res.message;
					if (res.code == '1' && res.data) {
						newArr = res.data.data;
					} else {
						this.$util.showToast({
							title: msg
						});
					}
					console.log(res)
					this.mescroll.endSuccess(newArr.length);
					//设置列表数据
					if (this.pagenum == 1) this.orderList = []; //如果是第一页需手动制空列表
					this.orderList = this.orderList.concat(newArr); //追加新数据
					// if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				},
				fail: res => {
					this.emptyType = 'order';
					this.emptyShow = true;
					// if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});
		},
		 allocationListLoadData(e) {
		 	var data = {
		 		status: this.tabObj.status,
		 		page: this.pagenum,
		 		page_size:this.pagesize,
		 	};
		 	// console.log(this.check.isLogin())
		 	this.emptyShow = false;
		 	this.http.sendRequest({
		 		api: this.api.order.allocationList,
		 		data: data,
		 		success: res => {
		 			this.emptyShow = true;
		 			this.emptyType = 'order';
		 			let newArr = [];
		 			let msg = res.message;
		 			if (res.code == '1' && res.data) {
		 				newArr = res.data.data;
		 			} else {
		 				this.$util.showToast({
		 					title: msg
		 				});
		 			}
		 			console.log(res)
		 			this.mescroll.endSuccess(newArr.length);
		 			//设置列表数据
		 			if (this.pagenum == 1) this.orderList = []; //如果是第一页需手动制空列表
		 			this.orderList = this.orderList.concat(newArr); //追加新数据
		 			if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
		 		},
		 		fail: res => {
		 			this.emptyType = 'order';
		 			this.emptyShow = true;
		 			if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
		 		}
		 	});	 
		 },
		toWaybillList(item) {
			console.log(item)
			this.$util.redirectTo('/pages/order/order-list/allocation-order-list', {
				journey_id: this.check.strNullReplace(item.journey_id,''), 
			});
		}, 
  
	}
};